home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / ubiquity / migration-assistant / ma-ask < prev    next >
Text File  |  2008-05-01  |  7KB  |  172 lines

  1. #!/bin/sh
  2.  
  3. # TODO: Incorporate capb backup.
  4.  
  5. set -e
  6. . /usr/share/debconf/confmodule
  7. . /usr/share/migration-assistant/ma-script-utils
  8.  
  9. if [ -z "$1" ]; then
  10.     mapath="/usr/bin"
  11. else
  12.     mapath="$1"
  13. fi
  14.  
  15. OLDIFS="$IFS"
  16. NEWLINE='
  17. '
  18.  
  19. IFS="$NEWLINE"
  20. tmp=
  21. for line in `os-prober`;
  22. do
  23.     dist=$(LC_ALL=C expr match "$line" '.*:\(.*\):.*:.*')
  24.     location=${line%%:*}
  25.     if [ -z "$tmp" ]; then
  26.         tmp="$dist ($location)"
  27.     else
  28.         tmp="$tmp, $dist ($location)"
  29.     fi
  30. done
  31. IFS="$OLDIFS"
  32.  
  33. db_subst migration-assistant/partitions choices "$tmp"
  34. db_input high migration-assistant/partitions || true
  35. db_go || exit 10
  36.  
  37. db_get migration-assistant/partitions || RET=
  38. IFS="$NEWLINE"
  39. selection=`echo "$RET" | sed -e 's/, /\n/g'`
  40. for choice in $selection; do # Microsoft Windows XP Professional (/dev/hda1)
  41.     IFS="$OLDIFS"
  42.     location=$(LC_ALL=C expr "$choice" : '.*(\(.*\))$') # /dev/hda1
  43.     IFS="$NEWLINE"
  44.     for line in `os-prober`; do
  45.         IFS="$OLDIFS"
  46.         loc="${line%%:*}"
  47.         if [ "$location" != "$loc" ]; then
  48.             continue
  49.         fi
  50.         log "setting ostype from: '$line'"
  51.         set_os_type "$line" || continue
  52.         log "got ostype of: '$ostype', mountpoint is: '$mountpoint'"
  53.  
  54.         path="${loc#*/*/}" # hda1 or discs/disc0/part1
  55.         mount_os "$ostype" "$loc"
  56.         db_register migration-assistant/users migration-assistant/$path/users
  57.         db_subst migration-assistant/$path/users user-choices \
  58.             "$($mapath/ma-search-users "$ostype" "$mountpoint" 2>>/var/log/syslog)"
  59.         db_subst migration-assistant/$path/users os-type "$choice"
  60.  
  61.         db_input high migration-assistant/$path/users || true
  62.         db_go || exit 10
  63.  
  64.         db_get migration-assistant/$path/users || RET=
  65.         
  66.         user_selection=`echo "$RET" | sed -e 's/, /\n/g'`
  67.         IFS="$NEWLINE"
  68.         for usr in $user_selection; do
  69.             IFS="$OLDIFS"
  70.             itemsret=$($mapath/ma-search-items --path="$mountpoint" --ostype="$ostype" --user="$usr" 2>>/var/log/syslog) || \
  71.                 (itemsret=; error "ma-search-items exited with an error for $usr.")
  72.             formatted_user=`echo "$usr" | sed -e 's/ /+/g'`
  73.             db_register migration-assistant/items migration-assistant/$path/$formatted_user/items
  74.             db_subst migration-assistant/$path/$formatted_user/items choices "$itemsret"
  75.             db_subst migration-assistant/$path/$formatted_user/items user "$usr"
  76.  
  77.             # migration-assistant/discs/disc0/part1/Evan/items
  78.             db_input high migration-assistant/$path/$formatted_user/items || true
  79.             db_go || exit 10
  80.  
  81.             db_register migration-assistant/user migration-assistant/$path/$formatted_user/user
  82.             # This prevents m-a from working right. change to choices
  83.             #db_set migration-assistant/$path/$formatted_user/user "$(echo "$usr" | tr '[A-Z]' '[a-z]')"
  84.             db_subst migration-assistant/$path/$formatted_user/user old-user "$usr"
  85.  
  86.             while :; do
  87.                 db_input high migration-assistant/$path/$formatted_user/user || true
  88.                 db_go || exit 10
  89.                 
  90.                 db_get migration-assistant/$path/$formatted_user/user || RET=
  91.                 new_user="$RET"
  92.                 
  93.                 if ! LC_ALL=C expr "$new_user" : '[a-z][-a-z0-9]*$' >/dev/null; then
  94.                     db_fset migration-assistant/$path/$formatted_user/user seen false
  95.                     db_fset migration-assistant/username-bad seen false
  96.                     db_subst migration-assistant/username-bad user "$new_user"
  97.                     db_input critical migration-assistant/username-bad
  98.                     continue
  99.                 fi
  100.                 
  101.                 # TODO: Either copy this or depend on user-setup.
  102.                 if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
  103.                    grep -q "^$new_user\$"; then
  104.                     db_fset migration-assistant/$path/$formatted_user/user seen false
  105.                     db_fset migration-assistant/username-reserved seen false
  106.                     db_subst migration-assistant/username-reserved user "$new_user"
  107.                     db_input critical migration-assistant/username-reserved
  108.                     continue
  109.                 fi
  110.                 break
  111.             done
  112.  
  113.             # Only ask if the user doesn't match the one seeded for user-setup.
  114.             db_get passwd/username || RET=
  115.             if [ "$new_user" = "$RET" ]; then
  116.                 continue
  117.             fi
  118.  
  119.             # Password
  120.             db_register migration-assistant/password migration-assistant/new-user/$new_user/password
  121.             db_subst migration-assistant/new-user/$new_user/password user "$new_user"
  122.  
  123.             db_register migration-assistant/password-again migration-assistant/new-user/$new_user/password-again
  124.             db_subst migration-assistant/new-user/$new_user/password-again user "$new_user"
  125.  
  126.             while :; do
  127.                 db_input high migration-assistant/new-user/$new_user/password || true
  128.                 db_go || exit 10
  129.                 db_get migration-assistant/new-user/$new_user/password || RET=
  130.                 pass=$RET
  131.  
  132.                 db_input high migration-assistant/new-user/$new_user/password-again || true
  133.                 db_go || exit 10
  134.                 db_get migration-assistant/new-user/$new_user/password-again || RET=
  135.                 pass2=$RET
  136.                 
  137.                 if [ -z "$pass2" ] || [ -z "$pass" ]; then
  138.                     db_set migration-assistant/new-user/$new_user/password ""
  139.                     db_set migration-assistant/new-user/$new_user/password-again ""
  140.                     db_fset migration-assistant/password-empty seen "false"
  141.                     db_input high migration-assistant/password-empty || true
  142.                     db_fset migration-assistant/new-user/$new_user/password seen "false"
  143.                     db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  144.                     db_go || true
  145.                     continue
  146.                 fi
  147.  
  148.                 if [ "$pass2" = "$pass" ]; then
  149.                     break
  150.                 else
  151.                     db_set migration-assistant/new-user/$new_user/password ""
  152.                     db_set migration-assistant/new-user/$new_user/password-again ""
  153.                     db_fset migration-assistant/password-mismatch seen "false"
  154.                     db_input high migration-assistant/password-mismatch || true
  155.                     db_fset migration-assistant/new-user/$new_user/password seen "false"
  156.                     db_fset migration-assistant/new-user/$new_user/password-again seen "false"
  157.                     db_go || true
  158.                 fi
  159.             done
  160.  
  161.             # Full Name
  162.             db_register migration-assistant/fullname migration-assistant/new-user/$new_user/fullname
  163.             db_subst migration-assistant/new-user/$new_user/fullname user "$new_user"
  164.             db_input high migration-assistant/new-user/$new_user/fullname || true
  165.             db_go || exit 10
  166.         done
  167.         IFS="$OLDIFS"
  168.         unmount_os
  169.     done
  170. done
  171. # vim:ai:et:sts=4:tw=80:sw=4:
  172.